import React from 'react';
import zhCN from 'antd/es/locale/zh_CN';
import { childConfig } from '@/config';
import { ConfigProvider } from 'antd';
import stores from '@/stores';
import {Provider} from 'mobx-react';
import { isInIcestark, getMountNode } from '@ice/stark-app';

const root = document.getElementById(childConfig.rootId);

// 设置弹出框（Select, Tooltip, Menu 等等）渲染父节点
function getPopupContainer() {
  return isInIcestark() ? getMountNode() : root;
}

//5.x版本严格模式开启方式，store的状态只能在store文件中修改
// configure({
//   enforceActions: "observed"
// });

export default function AntdConfigProvider({ children }: any): JSX.Element {
  return (
    <ConfigProvider
      prefixCls={childConfig.prefixCls}
      locale={zhCN}
      getPopupContainer={getPopupContainer}
    >
      <Provider {...stores}>
        {children}
      </Provider>
    </ConfigProvider>
  );
}
